Integration for DIS Example Application
This page page is under construction. |
Library Integration for DIS Example Application
Introduction
This example demonstrates how to stabilize a video using the Digital Image Stabilization (DIS) pipeline. It reads frames from a file or camera source using OpenCV, prepares them as RVS image objects, applies the DigitalStabilizer, and writes or displays the stabilized output.
Concept
The application implements a complete offline video stabilization pipeline. The process consists of opening an input source, configuring the stabilization parameters, preparing the input and output images, processing each frame through the DigitalStabilizer, and finally displaying or storing the stabilized output.
Instances
This application uses the following library components:
- An Optical Flow instance with Optical Flow parameters.
- A Smoothing instance with Smoothing parameters.
- A Geometric Transform instance.
- A DigitalStabilizer with DigitalStabilizer parameters.
- A HostAllocator or CudaAllocator, depending on the selected backend.
Preprocessing and Preparation
The input video is read from a file or camera source using OpenCV. Before processing begins, the application verifies that it is possible to:
- Open the input video.
- Create the output video file, if recording is enabled.
The input video properties, such as the frame size, frame rate, and codec, are obtained from the source and used to configure the output stream.
If these steps are successful, the application advances to the main processing loop.
Main Processing Loop
The main processing loop reads one frame at a time from the input source. Each frame goes through the following stages before the stabilized output is produced.
Preparing the Input and Output Images
Each captured frame is converted from the OpenCV BGR format to RGBA and wrapped as an RVS image object compatible with the selected backend.
For the OpenCV backend, the example wraps the images using the HostAllocator. For the CUDA backend, it uses persistent CudaAllocator images backed by pinned memory.
Applying the Stabilizer
Once the input and output images have been prepared, the application invokes the DigitalStabilizer.
For the OpenCV backend:
stab_ret =
stabilizer.Apply<HostAllocatorType>(
rvs_out,
rvs_frame);
For the CUDA backend:
stab_ret =
stabilizer.Apply<CudaAllocatorType>(
rvs_out_cuda,
rvs_frame_cuda);
The DigitalStabilizer internally executes the DIS pipeline by estimating frame-to-frame motion, smoothing the resulting motion, and applying the corresponding geometric transformation.
Processing the Output
The stabilized output is produced as an RGBA image. Before displaying or writing the frame using OpenCV, it is converted back to the BGR format.
If display mode is enabled, the stabilized frame is displayed. If recording is enabled, the stabilized frame is written to the output video file.
Cleanup
At the end of the process, the application releases its resources, prints performance statistics and summary information, and cleans up CUDA resources when the CUDA backend is used.